import isEmpty from 'lodash/isEmpty'
import cloneDeep from 'lodash/cloneDeep'
import { clipboard } from '@ve/utils/clipboard'
import { ElMessage } from 'element-plus'
import { translateTitle } from '@/utils/i18n'
//必须带done回调 执行完成调用
export default function copyTableCell({ additionalData, done }) {
  additionalData = cloneDeep(additionalData)
  if (!additionalData) {
    ElMessage({
      showClose: true,
      message: translateTitle('Ve.eventTask.复制单元格提示'),
      type: 'error',
    })
    done(null, {})
    return
  }
  let _field = additionalData.column.field || ''
  if (isEmpty(_field) && additionalData.column.type === 'seq') {
    _field = '#SEQ#'
    additionalData.row[_field] = additionalData.rowIndex + 1
  }
  let _value = additionalData.row[_field]

  clipboard(_value.toString())
  done(null, {})
}
